/*
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Topless JSF.
 *
 * The Initial Developer of the Original Code is
 * Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
 *
 * ***** END LICENSE BLOCK *****
 */

package kineteque.jsf.topless.jdbc;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.Serializable;

/**
 * A generic list result used for paging.
 */
public class PaginatedList<T> implements Serializable {

    /** The column names. */
    protected List<String> columnNames = null;
    /** The list to page through. */
    protected List<T> list;
    /** The match count. */
    protected int rows = 0;
    /** Addition properties that the user may want to add to this class. */
    protected Map<String, Object> properties = null;

    /**
     * Retrieves the column names.
     *
     * @return The column names.
     */
    public List<String> getColumnNames() {
        return columnNames;
    }

    /**
     * Assigns the column names.
     *
     * @param columnNames The column names.
     */
    public void setColumnNames(List<String> columnNames) {
        this.columnNames = columnNames;
    }

    /**
     * Retrieves the list to page through.
     *
     * @return the list to page through.
     */
    public List<T> getList() {
        if (list==null) {
            list = new ArrayList<T>();
        }
        return list;
    }

    /**
     * Sets the list to page through.
     *
     * @param list the list to page through.
     */
    public void setList(List<T> list) {
        this.list = list;
    }

    /**
     * Retrieves the match count.
     *
     * @return the match count.
     */
    public int getRows() {
        return rows;
    }

    /**
     * Sets the match count.
     *
     * @param rows the match count.
     */
    public void setRows(int rows) {
        this.rows = rows;
    }

    /**
     * Puts a property into this list result.
     *
     * @param name  The name of the property.
     * @param value The value.
     */
    public void put(String name, Object value) {
        if (properties == null) {
            properties = new HashMap<String,Object>();
        }
        properties.put(name, value);
    }

    /**
     * Retrieves a property from the list result.
     *
     * @param name The name of the property to retrieve.
     * @return The value retrieved.
     */
    public Object get(String name) {
        return properties == null ? null : properties.get(name);
    }

    /**
     * Retrieves the property map.
     *
     * @return The property map.
     */
    public Map<String, Object> getProperties() {
        if (properties==null) {
            properties = new HashMap<String,Object>();
        }
        return properties;
    }

    /**
     * Assigns the properties map.
     *
     * @param properties The properties map.
     */
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }
}
